home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
libgutil
/
homo2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
5KB
|
208 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* homo2 -
* Homogeneous mapping in 2 dimensions.
*
* Tom Davis - 1986
*/
#include "stdio.h"
float det3();
maptomat3(src,dst,mat)
float src[4][3], dst[4][3];
float mat[3][3];
{
float srctrans[3][3], dsttrans[3][3];
float inv[3][3];
if ((det3(src, 0, 1, 2) == 0.0) ||
(det3(src, 0, 1, 3) == 0.0) ||
(det3(src, 0, 2, 3) == 0.0) ||
(det3(src, 1, 2, 3) == 0.0) ||
(det3(dst, 0, 1, 2) == 0.0) ||
(det3(dst, 0, 1, 3) == 0.0) ||
(det3(dst, 0, 2, 3) == 0.0) ||
(det3(dst, 1, 2, 3) == 0.0)) {
printf("3 points in line\n");
return;
}
idmap(dst, dsttrans);
idmap(src, srctrans);
invertmat3(srctrans, inv);
matmult3(inv, dsttrans, mat);
}
mat3tomat4(mat3,mat4)
float mat3[3][3];
float mat4[4][4];
{
int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
mat4[i][j] = 0.0;
mat4[0][0] = mat3[0][0];
mat4[0][1] = mat3[0][1];
mat4[1][0] = mat3[1][0];
mat4[1][1] = mat3[1][1];
mat4[0][3] = mat3[0][2];
mat4[1][3] = mat3[1][2];
mat4[3][3] = mat3[2][2];
mat4[3][0] = mat3[2][0];
mat4[3][1] = mat3[2][1];
mat4[2][2] = 0.0;
}
identmat3(mat)
float mat[3][3];
{
mat[0][0] = 1.0;
mat[1][0] = 0.0;
mat[2][0] = 0.0;
mat[0][1] = 0.0;
mat[1][1] = 1.0;
mat[2][1] = 0.0;
mat[0][2] = 0.0;
mat[1][2] = 0.0;
mat[2][2] = 1.0;
}
normmat3(mat)
float mat[3][3];
{
float mag, del;
del = mat[2][2]-1.0;
if(del>0.0001 || del<-0.0001) {
mag = mat[2][2];
mat[0][0] /= mag;
mat[1][0] /= mag;
mat[2][0] /= mag;
mat[0][1] /= mag;
mat[1][1] /= mag;
mat[2][1] /= mag;
mat[0][2] /= mag;
mat[1][2] /= mag;
mat[2][2] = 1.0;
}
}
transpoint3(mat,x,y,tx,ty)
float mat[3][3], x, y;
float *tx, *ty;
{
float div;
div = (x*mat[0][2]+y*mat[1][2]+mat[2][2]);
*tx = (x*mat[0][0]+y*mat[1][0]+mat[2][0])/div;
*ty = (x*mat[0][1]+y*mat[1][1]+mat[2][1])/div;
}
idmap(image, trans)
float image[4][3], trans[3][3];
{
int i, j;
float theta[3], D;
D = det3(image, 0, 1, 2);
theta[0] = det3(image, 3, 1, 2)/D;
theta[1] = det3(image, 0, 3, 2)/D;
theta[2] = det3(image, 0, 1, 3)/D;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
trans[i][j] = image[i][j]*theta[i];
}
copymat3(smat,dmat)
float smat[3][3];
float dmat[3][3];
{
bcopy(smat,dmat,9*sizeof(float));
}
float det3(arr, i1, i2, i3)
float arr[][3];
int i1, i2, i3;
{
float det;
det = arr[i1][0]*(arr[i2][1]*arr[i3][2] - arr[i3][1]*arr[i2][2])
-arr[i1][1]*(arr[i2][0]*arr[i3][2] - arr[i3][0]*arr[i2][2])
+arr[i1][2]*(arr[i2][0]*arr[i3][1] - arr[i3][0]*arr[i2][1]);
return det;
}
printmat3(trans)
float trans[3][3];
{
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
printf("%f\t", trans[i][j]);
printf("\n");
}
printf("\n");
}
matmult3(x1, x2, prod)
float x1[3][3], x2[3][3], prod[3][3];
{
int i, j, k;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++) {
prod[i][j] = 0.0;
for (k = 0; k < 3; k++)
prod[i][j] += x1[i][k]*x2[k][j];
}
}
#define det2(a, b, c, d) ((a)*(d)-(b)*(c))
invertmat3(mat, matinv)
float mat[3][3], matinv[3][3];
{
float a, b, c, d, e, f, g, h, i;
float a1, a2, a3;
float det;
a = mat[0][0]; b = mat[0][1]; c = mat[0][2];
d = mat[1][0]; e = mat[1][1]; f = mat[1][2];
g = mat[2][0]; h = mat[2][1]; i = mat[2][2];
det = a*det2(e, f, h, i)
-b*det2(d, f, g, i)
+c*det2(d, e, g, h);
matinv[0][0] = det2(e, f, h, i)/det;
matinv[1][0] = -det2(d, f, g, i)/det;
matinv[2][0] = det2(d, e, g, h)/det;
matinv[0][1] = -det2(b, c, h, i)/det;
matinv[1][1] = det2(a, c, g, i)/det;
matinv[2][1] = -det2(a, b, g, h)/det;
matinv[0][2] = det2(b, c, e, f)/det;
matinv[1][2] = -det2(a, c, d, f)/det;
matinv[2][2] = det2(a, b, d, e)/det;
}